#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;

const int maxn=400;

ll min(ll a, ll b) {
	return a<b ? a : b;
}

ll max(ll a, ll b) {
	return a>b ? a : b;
}

int main() {
	freopen("snakes.in", "r", stdin);
	freopen("snakes.out", "w", stdout);

	static ll f[maxn+1][maxn+1];
	static int a[maxn+1];
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i=1; i<=n; i++) {
		scanf("%d", a+i);
	}
	k++;

	memset(f, 127, sizeof f);
	f[0][0] = 0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=k; j++) {
			ll sum=a[i], maxv=a[i];
			for (int x=i-1; x>=0; x--) {
				f[i][j] = min(f[i][j], f[x][j-1]+maxv*(i-x)-sum);
				sum += a[x], maxv = max(a[x], maxv);
			}
		}
	}
	
	printf("%lld", f[n][k]);

	fclose(stdin);
	fclose(stdout);
	return 0;
}
